# Contributor: Raed Rizqie <raed.rizqie@gmail.com>

_realname=python-lsp-server
pkgbase=mingw-w64-${_realname}
pkgname=${MINGW_PACKAGE_PREFIX}-${_realname}
pkgver=1.7.0
pkgrel=1
pkgdesc='Python Language Server for the Language Server Protocol (mingw-w64)'
arch=('any')
mingw_arch=('mingw32' 'mingw64' 'ucrt64' 'clang64' 'clang32')
license=('MIT')
url='https://github.com/python-lsp/python-lsp-server'
depends=(
    ${MINGW_PACKAGE_PREFIX}-python
    ${MINGW_PACKAGE_PREFIX}-python-docstring-to-markdown
    ${MINGW_PACKAGE_PREFIX}-python-jedi
    ${MINGW_PACKAGE_PREFIX}-python-lsp-jsonrpc
    ${MINGW_PACKAGE_PREFIX}-python-pluggy
    ${MINGW_PACKAGE_PREFIX}-python-setuptools
    ${MINGW_PACKAGE_PREFIX}-python-ujson
)
makedepends=(${MINGW_PACKAGE_PREFIX}-python-build
             ${MINGW_PACKAGE_PREFIX}-python-installer
             ${MINGW_PACKAGE_PREFIX}-python-setuptools-scm
             ${MINGW_PACKAGE_PREFIX}-python-wheel)
options=(!strip)
source=(https://pypi.org/packages/source/${_realname::1}/${_realname}/${_realname}-${pkgver}.tar.gz
        0001-python-lsp-server-1.5.0-allow-newlest-depends.patch)
sha256sums=('401ce78ea2e98cadd02d94962eb32c92879caabc8055b9a2f36d7ef44acc5435'
            'bd28174ce31d16f005c69b92ce98a435c9e93605e7c386d94fef7c745b0fe642')

prepare() {
  cd "${_realname}-${pkgver}"
  patch -p1 -i ${srcdir}/0001-python-lsp-server-1.5.0-allow-newlest-depends.patch

  cd "${srcdir}"
  rm -rf python-build-${MSYSTEM} | true
  cp -r "${_realname}-${pkgver}" "python-build-${MSYSTEM}"

  # Set version for setuptools_scm
  export SETUPTOOLS_SCM_PRETEND_VERSION=${pkgver}
}

build() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  ${MINGW_PREFIX}/bin/python -m build --wheel --skip-dependency-check --no-isolation
}

package() {
  cd "${srcdir}/python-build-${MSYSTEM}"

  MSYS2_ARG_CONV_EXCL="--prefix=" \
    ${MINGW_PREFIX}/bin/python -m installer --prefix=${MINGW_PREFIX} \
    --destdir="${pkgdir}" dist/*.whl

  install -Dm644 LICENSE "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE"
}
